﻿#include "queue.h"

// 初始化头结点
Queue* create_queue() {
	Queue* head = (Queue*)malloc(sizeof(Queue));
	head->next = NULL;
	return head;
}
// 入队函数：将一个数据节点插入队列的末尾
void push(Queue* head, struct exam* data) {
    Queue* p = head;

    while (p->next != NULL) {
        p = p->next;
    }
    Queue* newNode = (Queue*)malloc(sizeof(Queue));
    newNode->content = *data;
    newNode->next = NULL;
    p->next = newNode;
}

// 获取队列头的第一个数据
Queue* front(Queue* head) {
    // 如果队列为空（即只有头节点），返回头节点并提示
    if (head->next == NULL) {
        printf("队列是空的\n");
        return head;
    }
    return head->next;
}

// 出队
void pop(Queue* head) {
	if (head->next == NULL) {
		printf("队列是空的!\n");
		return;
	}
	Queue* p = head->next;
	head->next = head->next->next;
	free(p);
}

// 销毁队列
void destroy_queue(Queue* head) {
	Queue* p = head;
	while (p != NULL) {
		Queue* temp = p;
		p = p->next;
		free(temp);
	}
	head = NULL;  // 释放队列后将头指针置为NULL
}

